package com.tao.spell.group.controller;

import com.tao.spell.common.utils.PageUtils;
import com.tao.spell.common.utils.R;
import com.tao.spell.group.entity.GoodsEntity;
import com.tao.spell.group.service.GoodsService;
import com.tao.spell.group.util.Oss;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author lc
 * @email sunlightcs@gmail.com
 * @date 2021-09-10 20:29:10
 */
@RestController
@RequestMapping("group/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;


    @RequestMapping("/up")
    public String up(MultipartFile file) throws IOException {
        return Oss.up(file);

    }
    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{goodsId}")

    public R info(@PathVariable("goodsId") Integer goodsId){
		GoodsEntity goods = goodsService.getById(goodsId);

        return R.ok().put("goods", goods);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody GoodsEntity goods){
		goodsService.save(goods);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody GoodsEntity goods){
		goodsService.updateById(goods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Integer[] goodsIds){
		goodsService.removeByIds(Arrays.asList(goodsIds));

        return R.ok();
    }

}
